package com.sqly.doc.menu.ycf;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ihidea.multilinechooselib.MultiLineChooseLayout;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sqly.doc.R;
import com.sqly.doc.base.MyBaseActivity;
import com.sqly.doc.menu.camera.CameraChoose;
import com.sqly.doc.menu.tnb.tnb;
import com.sqly.doc.pojo.JuMin;
import com.sqly.doc.pojo.RetMsg;
import com.sqly.doc.pojo.YcfChfs;
import com.sqly.doc.pojo.YcfDewccqsf;
import com.sqly.doc.user.choose_user;
import com.sqly.doc.util.BinderUtil;
import com.sqly.doc.util.CreateBitmap;
import com.sqly.doc.util.DateConvert;
import com.sqly.doc.util.HttpUrl;
import com.sqly.doc.util.MyToastUtil;
import com.sqly.doc.util.NetWorkUtils;
import com.sqly.doc.util.SharedPreferencesUtils;
import com.sqly.doc.util.SweetAlertDialogUtil;
import com.sqly.doc.util.Url;
import com.sqly.doc.util.UserClient;
import com.sqly.doc.util.WriteActivity;
import com.sqly.doc.view.CustomDatePicker;
import com.sqly.doc.view.StringUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import cz.msebera.android.httpclient.Header;

//import cn.pedant.SweetAlert.SweetAlertDialog;


/**
 */

public class ycf_chfsjl extends MyBaseActivity {
    YcfChfs obj;
    private CustomDatePicker customDatePicker;
    Context con = ycf_chfsjl.this;
    //标题
    TextView title, uname;
    //内容
    TextView sfrq, fmrq, cyrq;
    EditText tw, ybjkqk, ybxlzk, xy1, xy2, rfyc, elyc, zgyc, skyc, qt, flyc, zdqt, yunci;
    RadioGroup rf, el, zg, sk, fl;
    MultiLineChooseLayout bjzd;
    private List<String> bjzddata = new ArrayList<>();
    //转诊
    //转诊
    EditText zzyy, jgjkb, lxr, lxdh;
    RadioGroup zzjg, zz;
    String zzjgs = "";
    TextView xcsfrq;
    LinearLayout back;

    String url="";
    String JKDAH="";
    ImageView sfysqm, brqm, xcqm;
    String sfysqmpic = "", brqmpic = "",xcqmpic ="";
    JuMin j;
    TextView xm;

    ImageView xcpaizhao;
    TextView pz_record_id,jmqm_record_id, ysqm_record_id;
    boolean pzChange = false;

    @Override
    protected void initUI() {
        setContentView(R.layout.ycf_chfsjlb);
        if (getIntent().getStringExtra("type").equals("edit")) {
            obj = (YcfChfs) getIntent().getExtras().getSerializable("b");
            url=HttpUrl.EditChsfjl;
            init();
            if(!StringUtils.isEmpty(obj.getImg())){
                //ImageLoader.getInstance().displayImage(Url.img_url()+obj.getImg(),brqm);
                ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg()),brqm);
            }
            if(!StringUtils.isEmpty(obj.getImg1())){
                //ImageLoader.getInstance().displayImage(Url.img_url()+obj.getImg1(),sfysqm);
                ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg1()),sfysqm);
            }
            if(!StringUtils.isEmpty(obj.getImg2())){
                //ImageLoader.getInstance().displayImage(Url.img_url()+obj.getImg2(),xcqm);
                ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg2()),xcqm);
            }
            xm.setClickable(false);
            yunci.setFocusable(false);
            yunci.setFocusableInTouchMode(false);
            //brqm.setClickable(false);
            //sfysqm.setClickable(false);
        }else{
            url=HttpUrl.AddYcfChfsjl;
            obj = new YcfChfs();
            init();
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {

        } else {
            if (requestCode == 1) {
                j = (JuMin) data.getExtras().getSerializable("j");
                getObject();
            }else if (requestCode == 8) {
                String record_id = (String) data.getExtras().getString("record_id");
                ysqm_record_id.setText(record_id);
                byte[] bis = data.getByteArrayExtra("bitmap");
                Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
                sfysqm.setImageBitmap(bb);
                sfysqmpic = CreateBitmap.saveMyBitmap(bb);
            }else if (requestCode == 9) {
                String record_id = (String) data.getExtras().getString("record_id");
                jmqm_record_id.setText(record_id);
                byte[] bis = data.getByteArrayExtra("bitmap");
                Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
                brqm.setImageBitmap(bb);
                brqmpic = CreateBitmap.saveMyBitmap(bb);
            }else if(requestCode == 119){
                String img_record_id = (String) data.getExtras().getString("img_record_id");
                pz_record_id.setText(img_record_id);
                pzChange = true;
                byte[] bis = data.getByteArrayExtra("bitmap");
                Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
                xcqm.setImageBitmap(bb);
            }
        }
    }

    public void init() {
        Log.i("obj", ""+(obj==null));
        yunci = (EditText) findViewById(R.id.yc);
        if (obj != null && !StringUtils.isEmpty(obj.getYUNCI())) {
            yunci.setText(obj.getYUNCI());
        }
        yunci.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                obj.setJKDAH("");
                obj.setXINGMING("");
                obj.setCARDNUM("");
                JKDAH = "";
                xm.setText("");
            }
        });
        xm = (TextView) findViewById(R.id.XINGMING);
        if (obj != null && !StringUtils.isEmpty(obj.getXINGMING())) {
            xm.setText(obj.getXINGMING());
        }else {
            xm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(null != yunci && StringUtils.isEmpty(yunci.getText().toString())){
                        MyToastUtil.ShowToast(con, "请先输入孕次");
                    }else if(!BinderUtil.isZzs(yunci.getText().toString())){
                        MyToastUtil.ShowToast(con, "孕次必须为正整数");
                    }else {
                        startActivityForResult(new Intent(con, choose_user.class).putExtra("cname", "ycf_chfsjl.class"), 1);
                    }
                }
            });
        }
        sfysqm = (ImageView) findViewById(R.id.sfysqm);
        if(obj!=null&&!StringUtils.isEmpty(obj.getSfysqm())){
            sfysqmpic=obj.getSfysqm();
            sfysqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/"+sfysqmpic+".jpg"));
        }
        sfysqm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(con, WriteActivity.class)
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "ycfchsf")
                        .putExtra("imageType", "img1")
                        .putExtra("class","ycf_chfsjl.class"), 8);
            }
        });
        brqm = (ImageView) findViewById(R.id.brqm);
        if(obj!=null&&!StringUtils.isEmpty(obj.getBrqm())){
            brqmpic=obj.getBrqm();
            brqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/"+brqmpic+".jpg"));
        }
        brqm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(con, WriteActivity.class)
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "ycfchsf")
                        .putExtra("imageType", "img")
                        .putExtra("class","ycf_chfsjl.class"), 9);
            }
        });
        xcqm = (ImageView) findViewById(R.id.xcqm);
        if (obj != null && !StringUtils.isEmpty(obj.getXcqm())) {
            xcqmpic = obj.getXcqm();
            xcqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + xcqmpic + ".jpg"));
        }
        xcqm.setOnClickListener(new CustomerListener());
        //现场拍照
        xcpaizhao = (ImageView) findViewById(R.id.xcpaizhao);
        xcpaizhao.setOnClickListener(new CustomerListener());
        //现场拍照照片id
        pz_record_id = (TextView) findViewById(R.id.pz_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg2())) {
            //fjhdycrhsf/D24E75C5BB5E417EBE65494CA09BF399.jpg
            String[] img2Arr =obj.getImg2().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                pz_record_id.setText(img2Arr[1]);
            }
        }
        jmqm_record_id= (TextView) findViewById(R.id.jmqm_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg())) {
            String[] img2Arr =obj.getImg().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                jmqm_record_id.setText(img2Arr[1]);
            }
        }
        ysqm_record_id= (TextView) findViewById(R.id.ysqm_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg1())) {
            //fjhdycrhsf/D24E75C5BB5E417EBE65494CA09BF399.jpg
            String[] img2Arr =obj.getImg1().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                ysqm_record_id.setText(img2Arr[1]);
            }
        }

        //转诊
        zzyy = (EditText) findViewById(R.id.zz_yy);
        if (obj != null && !StringUtils.isEmpty(obj.getZZYY())) {
            zzyy.setText(obj.getZZYY());
        }
        jgjkb = (EditText) findViewById(R.id.zzjg);
        if (obj != null && !StringUtils.isEmpty(obj.getZZJG())) {
            jgjkb.setText(obj.getZZJG());
        }
        lxr = (EditText) findViewById(R.id.zz_lxr);
        if (obj != null && !StringUtils.isEmpty(obj.getZZLXR())) {
            lxr.setText(obj.getZZLXR());
        }

        lxdh = (EditText) findViewById(R.id.zz_lxfs);
        if (obj != null && !StringUtils.isEmpty(obj.getZZLXFS())) {
            lxdh.setText(obj.getZZLXFS());
        }
        zzjg = (RadioGroup) findViewById(R.id.jg);
        if (obj != null && !StringUtils.isEmpty(obj.getZZJG())) {
            switch (Integer.parseInt(obj.getZZJG())) {
                case 1:
                    zzjg.check(R.id.dw);
                    break;
                case 2:
                    zzjg.check(R.id.wdw);
                    break;
            }
        }
        zzjg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.dw)
                    obj.setZZJG("1");
                else
                    obj.setZZJG("2");
            }
        });
        zz = (RadioGroup) findViewById(R.id.zz);
        if (obj != null && !StringUtils.isEmpty(obj.getSFZZ())) {
            switch (Integer.parseInt(obj.getSFZZ())) {
                case 1:
                    zz.check(R.id.zz_wu);
                    break;
                case 2:
                    zz.check(R.id.zz_you);
                    break;
            }
        }
        zz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.zz_wu)
                    obj.setSFZZ("1");
                else
                    obj.setSFZZ("2");
            }
        });
        xcsfrq = (TextView) findViewById(R.id.xcsfrq);
        if (obj != null && !StringUtils.isEmpty(obj.getXCSFRQ())) {
            xcsfrq.setText(DateConvert.dateToString(DateConvert.toDate(obj.getXCSFRQ(), DateConvert.YMD), DateConvert.YMD)+"");
        }
        xcsfrq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        xcsfrq.setText(time.split(" ")[0]);
                    }
                }, DateConvert.getCustomDatePickerStartRq(), DateConvert.getCustomDatePickerEndRq()); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(DateConvert.getCustomDatePickerNowRq());
            }
        });
        //标题
        title = (TextView) findViewById(R.id.title);
        uname = (TextView) findViewById(R.id.uname);
        title.setText("产后访视记录");
        uname.setText("保存");
        uname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null != yunci && StringUtils.isEmpty(yunci.getText().toString())){
                    MyToastUtil.ShowToast(con, "请输入孕次");
                }else if(!BinderUtil.isZzs(yunci.getText().toString())){
                    MyToastUtil.ShowToast(con, "孕次必须为正整数");
                }else if(null == xm.getText().toString() || "".equals(xm.getText().toString())){
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "姓名不能为空");
                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "ysqm", "0").toString()) && ysqm_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "随访医生签名不能为空");
                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "jmqm", "0").toString()) && jmqm_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "家属或本人签名不能为空");
                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "xcpz", "0").toString()) && pz_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "现场拍照不能为空");
                }else if(null == sfrq.getText().toString() || "".equals(sfrq.getText().toString())){
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "随访日期不能为空");
                } else if(null == xcsfrq.getText().toString() || "".equals(xcsfrq.getText().toString())){
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "下次随访日期不能为空");
                } else {
                    if (obj == null) {
                        obj = new YcfChfs();
                    }
                    obj.setYUNCI(yunci.getText().toString());
                    obj.setSFRQ(sfrq.getText().toString());
                    obj.setFMRQ(fmrq.getText().toString());
                    obj.setCYRQ(cyrq.getText().toString());
                    obj.setTIWEN(tw.getText().toString());
                    obj.setYBJKQK(ybjkqk.getText().toString());
                    obj.setYBXLQK(ybxlzk.getText().toString());
                    obj.setXUEYA1(xy1.getText().toString());
                    obj.setXUEYA2(xy2.getText().toString());
                    obj.setRUFANGYC(rfyc.getText().toString());
                    obj.setELUYC(elyc.getText().toString());
                    obj.setZIGONGYC(zgyc.getText().toString());
                    obj.setSHANGKOUYC(skyc.getText().toString());
                    obj.setQITA(qt.getText().toString());
                    obj.setFLYC(flyc.getText().toString());
                    ArrayList<Integer> zdlist = bjzd.getAllItemSelectedIndex();
                    String bjzds = "";
                    for (int i = 0; i < zdlist.size(); i++) {
                        if (i == 0)
                            bjzds = zdlist.get(i) + "";
                        else
                            bjzds = bjzds + "," + zdlist.get(i);
                    }
                    obj.setZHIDAO(bjzds);
                    obj.setZHIDAOQT(zdqt.getText().toString());
                    obj.setZZYY(zzyy.getText().toString());
                    obj.setZZJGJKS(jgjkb.getText().toString());
                    obj.setZZLXR(lxr.getText().toString());
                    obj.setZZLXFS(lxdh.getText().toString());
                    obj.setXCSFRQ(xcsfrq.getText().toString());
                    if (NetWorkUtils.isNetworkConnected(con)) {
                        ///网络连接
                        RequestParams ps = new RequestParams();
                        ps.add("entity.YUNCI", obj.getYUNCI());
                        ps.add("entity.SFRQ", obj.getSFRQ());
                        ps.add("entity.FMRQ", obj.getFMRQ());
                        ps.add("entity.CYRQ", obj.getCYRQ());
                        ps.add("entity.TIWEN", obj.getTIWEN());
                        ps.add("entity.YBJKQK", obj.getYBJKQK());
                        ps.add("entity.YBXLQK", obj.getYBXLQK());
                        ps.add("entity.XUEYA1", obj.getXUEYA1());
                        ps.add("entity.XUEYA2", obj.getXUEYA2());
                        ps.add("entity.RUFANGYC", obj.getRUFANGYC());
                        ps.add("entity.ELUYC", obj.getELUYC());
                        ps.add("entity.ZIGONGYC", obj.getZIGONGYC());
                        ps.add("entity.SHANGKOUYC", obj.getSHANGKOUYC());
                        ps.add("entity.QITA", obj.getQITA());
                        ps.add("entity.FLYC", obj.getFLYC());
                        ps.add("entity.ZHIDAO", obj.getZHIDAO());
                        ps.add("entity.ZHIDAOQT", obj.getZHIDAOQT());
                        ps.add("entity.SFZZ", obj.getSFZZ());
                        ps.add("entity.ZZYY", obj.getZZYY());
                        ps.add("entity.ZZJGJKS", obj.getZZJGJKS());
                        if (getIntent().getStringExtra("type").equals("edit"))
                            ps.add("entity.SFJLH",obj.getSFJLH());
                        else
                            ps.add("entity.JKDAH",JKDAH);
                        ps.add("entity.ZZLXR", obj.getZZLXR());
                        ps.add("entity.ZZLXFS", obj.getZZLXFS());
                        ps.add("entity.ZZJG", obj.getZZJG());
                        ps.add("entity.XCSFRQ", obj.getXCSFRQ());
                        ps.add("entity.XINGMING",obj.getXINGMING());
                        ps.add("entity.CARDNUM",obj.getCARDNUM());
                        ps.add("type","2");
                        ps.add("token",SharedPreferencesUtils.getParam(con,"token","").toString());

                        ps.add("pz_record_id", pz_record_id.getText().toString());
                        ps.add("jmqm_record_id", jmqm_record_id.getText().toString());
                        ps.add("ysqm_record_id", jmqm_record_id.getText().toString());
                        ps.add("entity.UPDATETIME", obj.getUPDATETIME());
                        //ycf_chfsjl.super.ImageUploadOperate(sfysqmpic, brqmpic, ps);
                        UserClient.get(url, ps, new AsyncHttpResponseHandler() {
                            @Override
                            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                                String content = new String(response);
                                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                                if (ret.getCode().equals("200")) {
                                    MyToastUtil.ShowToast(con, "成功");
                                }else{
                                    MyToastUtil.ShowToast(con, ret.getInfo());
                                }
                                finish();
                            }

                            @Override
                            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                                MyToastUtil.ShowToast(con, "失败");
                            }
                        });
                    }
                }
            }
        });
        back = (LinearLayout) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(pzChange){
                   SweetAlertDialogUtil.WarningDialogHaveCancelAndConfirm(con,"你确认不保存数据更新吗？","现场拍照已经采集，请注意点击“保存”","确定", "返回");
                }else {
                    finish();
                }
            }
        });
        ////////////////////////////////////////////////////////////////////////////////////////////
        sfrq = (TextView) findViewById(R.id.sfrq);
        if (obj != null && !StringUtils.isEmpty(obj.getSFRQ())) {
            sfrq.setText(DateConvert.dateToString(DateConvert.toDate(obj.getSFRQ(), DateConvert.YMD), DateConvert.YMD)+"");
        }
        sfrq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                String now = sdf.format(new Date());
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        sfrq.setText(time.split(" ")[0]);
                    }
                }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(now);
            }
        });
        fmrq = (TextView) findViewById(R.id.fmrq);
        if (obj != null && !StringUtils.isEmpty(obj.getFMRQ())) {
            fmrq.setText(obj.getFMRQ());
        }
        fmrq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                String now = sdf.format(new Date());
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        fmrq.setText(time.split(" ")[0]);

                    }
                }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(now);
            }
        });
        cyrq = (TextView) findViewById(R.id.cyrq);
        if (obj != null && !StringUtils.isEmpty(obj.getCYRQ())) {
            cyrq.setText(obj.getCYRQ());
        }
        cyrq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                String now = sdf.format(new Date());
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        cyrq.setText(time.split(" ")[0]);

                    }
                }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(now);
            }
        });

        tw = (EditText) findViewById(R.id.tw);
        if (obj != null && !StringUtils.isEmpty(obj.getTIWEN())) {
            tw.setText(obj.getTIWEN());
        }
        ybjkqk = (EditText) findViewById(R.id.ybjkqk);
        if (obj != null && !StringUtils.isEmpty(obj.getYBJKQK())) {
            ybjkqk.setText(obj.getYBJKQK());
        }
        ybxlzk = (EditText) findViewById(R.id.ybxlzk);
        if (obj != null && !StringUtils.isEmpty(obj.getYBXLQK())) {
            ybxlzk.setText(obj.getYBXLQK());
        }
        ybxlzk = (EditText) findViewById(R.id.ybxlzk);
        if (obj != null && !StringUtils.isEmpty(obj.getYBXLQK())) {
            ybxlzk.setText(obj.getYBXLQK());
        }
        xy1 = (EditText) findViewById(R.id.xy1);
        if (obj != null && !StringUtils.isEmpty(obj.getXUEYA1())) {
            xy1.setText(obj.getXUEYA1());
        }
        xy2 = (EditText) findViewById(R.id.xy2);
        if (obj != null && !StringUtils.isEmpty(obj.getXUEYA2())) {
            xy2.setText(obj.getXUEYA2());
        }

        /////d带有异常信息的
        rf = (RadioGroup) findViewById(R.id.rf);
        if (obj != null && !StringUtils.isEmpty(obj.getRUFANG())) {
            switch (Integer.parseInt(obj.getRUFANG())) {
                case 1:
                    rf.check(R.id.rf_wu);
                    break;
                case 2:
                    rf.check(R.id.rf_you);
                    break;

            }
        }
        rf.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.rf_wu) {
                    obj.setRUFANG("1");
                } else {
                    obj.setRUFANG("2");
                }
            }
        });
        rfyc = (EditText) findViewById(R.id.rf_yc);
        if (obj != null && !StringUtils.isEmpty(obj.getRUFANGYC())) {
            rfyc.setText(obj.getRUFANGYC());
        }


        el = (RadioGroup) findViewById(R.id.el);
        if (obj != null && !StringUtils.isEmpty(obj.getRUFANG())) {
            switch (Integer.parseInt(obj.getRUFANG())) {
                case 1:
                    el.check(R.id.el_wu);
                    break;
                case 2:
                    el.check(R.id.el_you);
                    break;

            }
        }
        el.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.el_wu) {
                    obj.setELU("1");
                } else {
                    obj.setELU("2");

                }
            }
        });
        elyc = (EditText) findViewById(R.id.el_yc);
        if (obj != null && !StringUtils.isEmpty(obj.getELUYC())) {
            elyc.setText(obj.getELUYC());
        }


        zg = (RadioGroup) findViewById(R.id.zg);
        if (obj != null && !StringUtils.isEmpty(obj.getZIGONG())) {
            switch (Integer.parseInt(obj.getZIGONG())) {
                case 1:
                    zg.check(R.id.zg_wu);
                    break;
                case 2:
                    zg.check(R.id.zg_you);
                    break;

            }
        }
        zg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.zg_wu) {
                    obj.setZIGONG("1");
                } else {
                    obj.setZIGONG("2");

                }
            }
        });
        zgyc = (EditText) findViewById(R.id.zg_yc);
        if (obj != null && !StringUtils.isEmpty(obj.getZIGONGYC())) {
            zgyc.setText(obj.getZIGONGYC());
        }

        sk = (RadioGroup) findViewById(R.id.sk);
        if (obj != null && !StringUtils.isEmpty(obj.getSHANGKOU())) {
            switch (Integer.parseInt(obj.getSHANGKOU())) {
                case 1:
                    sk.check(R.id.sk_wu);
                    break;
                case 2:
                    sk.check(R.id.sk_you);
                    break;

            }
        }
        sk.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.sk_wu) {
                    obj.setSHANGKOU("1");
                } else {
                    obj.setSHANGKOU("2");

                }
            }
        });
        skyc = (EditText) findViewById(R.id.sk_yc);
        if (obj != null && !StringUtils.isEmpty(obj.getSHANGKOUYC())) {
            skyc.setText(obj.getSHANGKOUYC());
        }
        qt = (EditText) findViewById(R.id.qt);
        if (obj != null && !StringUtils.isEmpty(obj.getQITA())) {
            qt.setText(obj.getQITA());
        }

        fl = (RadioGroup) findViewById(R.id.fl);
        if (obj != null && !StringUtils.isEmpty(obj.getFENLEI())) {
            switch (Integer.parseInt(obj.getFENLEI())) {
                case 1:
                    fl.check(R.id.fl_wu);
                    break;
                case 2:
                    fl.check(R.id.fl_you);
                    break;

            }
        }
        fl.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.fl_wu) {
                    obj.setFENLEI("1");
                } else {
                    obj.setFENLEI("2");

                }
            }
        });
        flyc = (EditText) findViewById(R.id.fl_yc);
        if (obj != null && !StringUtils.isEmpty(obj.getFLYC())) {
            flyc.setText(obj.getFLYC());
        }

        bjzd = (MultiLineChooseLayout) findViewById(R.id.zd);
        bjzddata.add("个人卫生");
        bjzddata.add("心理");
        bjzddata.add("营养");
        bjzddata.add("母乳喂养");
        bjzddata.add("新生儿护理与喂养");
        bjzddata.add("其他");
        bjzd.setList(bjzddata);
        if (obj != null && !StringUtils.isEmpty(obj.getZHIDAO())) {
            if (obj.getZHIDAO().contains("1"))
                bjzd.setIndexItemSelected(0);
            if (obj.getZHIDAO().contains("2"))
                bjzd.setIndexItemSelected(1);
            if (obj.getZHIDAO().contains("3"))
                bjzd.setIndexItemSelected(2);
            if (obj.getZHIDAO().contains("4"))
                bjzd.setIndexItemSelected(3);
            if (obj.getZHIDAO().contains("5"))
                bjzd.setIndexItemSelected(4);
            if (obj.getZHIDAO().contains("6"))
                bjzd.setIndexItemSelected(5);
        }

        zdqt = (EditText) findViewById(R.id.zd_qt);
        if (obj != null && !StringUtils.isEmpty(obj.getZHIDAOQT())) {
            zdqt.setText(obj.getZHIDAOQT());
        }

    }
    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    public void getObject() {
        RequestParams ps = new RequestParams();
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("type", "2");
        ps.add("yunci", yunci.getText().toString());
        ps.add("CARDNUM",j.getCARDNUM());
        UserClient.get(HttpUrl.GetYcfChfsjlGrjbxx, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                Log.i("ycf2",content);
                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                if (ret.getCode().equals("200")) {
                    if(StringUtils.isEmpty(ret.getOtherParams())){//other是空的
                        JSONObject j=JSON.parseObject(ret.getRd());
                        obj=new YcfChfs();
                        obj.setJKDAH(j.getString("JKDAH"));
                        obj.setXINGMING(j.getString("XINGMING"));
                        obj.setCARDNUM(j.getString("CARDNUM"));
                        JKDAH=j.getString("JKDAH");
                        xm.setText(j.getString("XINGMING"));
                    }
                } else{
                    SweetAlertDialogUtil.ErrorDialogNoFinish(con, "错误提示", ret.getInfo(), "确定");
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                obj = new YcfChfs();
            }
        });
    }
    class CustomerListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            if (obj != null && StringUtils.isEmpty(obj.getJKDAH())) {
                SweetAlertDialogUtil.WarningDialog(con, "提示", "选择居民用户后才能现场拍照");
            } else {
                Intent intent = new Intent(con, CameraChoose.class)
                        .putExtra("type", "edit")
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null == obj.getSFJLH() || "".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "ycfchsf")
                        .putExtra("class", "ycf_chfsjl.class");
                startActivityForResult(intent, 119);
            }
        }
    }
}
